package com.ruoyi.web.controller.community;

import java.util.List;

import com.ruoyi.community.domain.HeartFamilyInfo;
import com.ruoyi.community.service.IHeartFamilyInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家属信息Controller
 * 
 * @author Gaotian
 * @date 2021-12-16
 */
@RestController
@RequestMapping("/community/info")
public class HeartFamilyInfoController extends BaseController
{
    @Autowired
    private IHeartFamilyInfoService heartFamilyInfoService;

    /**
     * 查询家属信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HeartFamilyInfo heartFamilyInfo)
    {
        startPage();
        List<HeartFamilyInfo> list = heartFamilyInfoService.selectHeartFamilyInfoList(heartFamilyInfo);
        return getDataTable(list);
    }

    /**
     * 导出家属信息列表
     */
    @Log(title = "家属信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HeartFamilyInfo heartFamilyInfo)
    {
        List<HeartFamilyInfo> list = heartFamilyInfoService.selectHeartFamilyInfoList(heartFamilyInfo);
        ExcelUtil<HeartFamilyInfo> util = new ExcelUtil<HeartFamilyInfo>(HeartFamilyInfo.class);
        return util.exportExcel(list, "家属信息数据");
    }

    /**
     * 获取家属信息详细信息
     */
    @GetMapping(value = "/{familyid}")
    public AjaxResult getInfo(@PathVariable("familyid") Long familyid)
    {
        return AjaxResult.success(heartFamilyInfoService.selectHeartFamilyInfoById(familyid));
    }

    /**
     * 新增家属信息
     */
    @Log(title = "家属信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HeartFamilyInfo heartFamilyInfo)
    {
        return toAjax(heartFamilyInfoService.insertHeartFamilyInfo(heartFamilyInfo));
    }

    /**
     * 修改家属信息
     */
    @Log(title = "家属信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HeartFamilyInfo heartFamilyInfo)
    {
        return toAjax(heartFamilyInfoService.updateHeartFamilyInfo(heartFamilyInfo));
    }

    /**
     * 删除家属信息
     */
    @Log(title = "家属信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{familyids}")
    public AjaxResult remove(@PathVariable Long[] familyids)
    {
        return toAjax(heartFamilyInfoService.deleteHeartFamilyInfoByIds(familyids));
    }
}
